<%@page import="com.carple.dto.Member"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
 
<!DOCTYPE html>

<html>
<head>
	<meta charset="utf-8" />
	<title>글쓰기</title>
	<link rel="Stylesheet" href="/carple/styles/main.css" />
	<link rel="Stylesheet" href="/carple/styles/default.css" />
	<link rel="Stylesheet" href="/carple/styles/input2.css" />
	<script type="text/javascript">
	function checkAndSubmit() {
		var message ="";
		var header1 = document.getElementById("header1");
		var header2 = document.getElementById("header2");
		
		
		if(header1.value.length == 0 && header2.value.length == 0 ){
			message += "머릿말을 선택하세요.\r\n";
		}

		var title = document.getElementById("title");
		if(title.value.length == 0){
			message += "제목을 입력해주세요.\r\n";
		}else if(title.value.length > 20){
			message += "제목이 너무 깁니다.\n 제목을 20자 이내로 줄여주세요\r\n"
		}

		var content = document.getElementById("content");
		if(content.value.length == 0){
			message += "내용을 입력해주세요.\r\n";
		}else if(content.value.length > 1000){
			message += "내용이 1000자를 넘었습니다.\n 내용을 1000자 이내로 적어주세요.\r\n";
		}
		
		if (message.length >0) {
			alert(message);
		}else {
			document.getElementById("registerform").submit();
		}
		
		
		
		/* form.action = "/carple/board/boardwrite.action";
		form.submit(); */
		
	}
	</script>	
</head>
<body>
	<% pageContext.include("/WEB-INF/views/include/header.jsp"); %>
	<br /><br /><br /><br /><br /><br />
	<div id="pageContainer">		
		<div style="padding-top:25px;text-align:center">
		<div id="inputcontent">
		    <div id="inputmain">
		        <div class="inputsubtitle">게시판 글 쓰기</div>
		        <form id="registerform" action="write.action" method="post">
		        <table>
		            <tr>
		                <th>머릿말</th>
		                <td>
		                    <input id="header1" type="radio" name="header" value="Driver" checked="checked" />Driver
		                    <input id="header2" type="radio" name="header" value="Walker"/>Walker
		                </td>
		            </tr>
		            <tr>
		                <th>제목</th>
		                <td>
		                    <input id="title" type="text" name="title" style="width:280px" />
		                </td>
		            </tr>
		            <tr>
		                <th>작성자</th>
		                <td>
		                	<%=((Member)session.getAttribute("loginuser")).getEmailId()%> 
		                </td>
		            </tr>
		            <tr>
		                <th>내용</th>
		                <td>		                    
		                    <textarea id="content" name="content" cols="76" rows="15"></textarea>
		                </td>
		            </tr>
		        </table>
		        <div class="buttons">
		        	<!-- 아래 a 링크는 input type='submit' 버튼을 누르는 효과 발생 -->		        	
		        	<!--<a id="writebutton" href="javascript:document.forms[0].submit();">글쓰기</a>  -->
		        	<input type="button" style="width: 100px; height: 25px;" name="writebutton" value="write" onclick="checkAndSubmit();" />
		        	&nbsp;&nbsp;
		        	<!-- <a href="/carple/board/list.action">목록보기</a> -->
		        	<input type="button" style="width: 100px; height: 25px;" name="cancelbutton" value="cancel" onclick="location.href='/carple/board/list.action';"/>
		        </div>
		        </form>
		    </div>
		</div>   	
	
	</div>
	</div>

</body>
</html>